from django.db import models
from thinghoo_library.models import TimeModel
# from django.contrib.auth.models import User
from user.models import CdUser
from django.urls import reverse
from server.models import Server

# Create your models here.


class Product(TimeModel):
    name = models.CharField(verbose_name='产品名称', max_length=255, unique=True)
    description = models.TextField()
    created_user = models.ForeignKey(CdUser, verbose_name='创建者', on_delete=models.CASCADE)
    server = models.ForeignKey(Server, name='server', verbose_name='发布服务器', on_delete=models.DO_NOTHING)

    def __str__(self):
        return f'<Product {self.name}>'

    def get_absolute_url(self):
        return reverse("product-detail", kwargs={"pk": self.pk})
